package cn.itcast.service.impl;

import cn.itcast.dao.AddressDao;
import cn.itcast.pojo.Address;
import cn.itcast.service.AddressService;
import com.alibaba.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ObjectUtils;

import java.util.List;


@Service(version = "1.0.0")
public class AddressServiceImpl implements AddressService {

    @Autowired
    private AddressDao addressDao;

    /**
     * 查询所有的分院地址
     *
     * @return
     */
    @Override
    public List<Address> findAll() {
        return addressDao.findAll();

    }

    @Transactional
    @Override
    public int submit(Address address) {
        if (ObjectUtils.isEmpty(address.getId())){
            return addressDao.submit(address) ;
        }else {
            return this.update(address);
        }
    }



    @Override
    public Address findById(Integer id) {
        Address address = this.addressDao.findById(id);
        if(address!=null){
            return address;
        }
        return null;
    }

    @Override
    public int delete(Integer id) {
        int count = 0;
        count = this.addressDao.delete(id);
        if(count!=0){
            return count;
        }
        return count;
    }

    @Override
    public int update(Address address) {

        return this.addressDao.update(address);

    }

    //是否启用
    @Override
    public void updateEnable(Integer id ,Integer enable) {
        addressDao.updateEnable(id,enable);
    }
}
